package com.hllxd.hism.star.basic.service.service;

import com.alibaba.fastjson.JSON;
import com.hllxd.hism.star.basic.service.dao.mapper.mis.AlertRuleMapper;
import com.hllxd.hism.star.basic.service.model.AlertRuleEntity;
import com.hllxd.hism.star.basic.service.util.TimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 计算任务白名单管理
 * @author xiyong.lxy
 * @date 2020-10-12 16:51
 */
@Slf4j
@Service("alertRuleService")
public class AlertRuleServiceImpl implements AlertRuleService {

    @Autowired
    private AlertRuleMapper alertRuleMapper;


    @Override public AlertRuleEntity getAlertPolicy(Long id, String ruleCode) {
        return alertRuleMapper.getAlertPolicy(id, ruleCode);
    }

    @Override
    public Long setAlertPolicy(AlertRuleEntity entity) {
        log.info("set param: {}", JSON.toJSONString(entity));
        if(entity.id==null || entity.id==0) {
            log.info("will insert entity.");
            return alertRuleMapper.insertAlertPolicy(entity);
        } else {
            log.info("will update entity.");
            entity.action = 1;
            entity.actionTime = TimeUtil.currentTimeHllDT();
            return alertRuleMapper.updateAlertPolicy(entity);
        }
    }

    @Override
    public List<AlertRuleEntity> listAlertPolicy() {
        return alertRuleMapper.listAlertPolicy();
    }

    @Override
    public Boolean deleteAlertPolicy(String ids) {
        return alertRuleMapper.deleteAlertPolicy(ids);
    }
}
